package com.boot.ys.mybatisplus.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;

//定时任务
//SpringBoot整合定时任务
@Slf4j
@Configuration      //1.主要用于标记配置类，兼备Component的效果。
@EnableScheduling   // 2.开启定时任务
@RestController
public class Task {

    @Scheduled(cron = "0 0 0 * * ?")
    public void Test(){
        Date date = new Date();
        SimpleDateFormat testDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = testDate.format(date);
        System.out.println("现在是北京时间:"+format);
        log.info("现在是北京时间现在是北京时间"+format);
        System.out.println("定时任务执行了"+new Date());
    }

}
